import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '../components/Login'
import Home from '../components/Home'
import Welcome from "../components/Welcome";
import User from "../components/user/User";
import Rights from "../components/power/Rights";
import Roles from "../components/power/Roles";
import Cate from "../components/goods/Cate";
import Params from "../components/goods/Params.vue";



Vue.use(VueRouter)



// const routes = [
//     { path: '/', redirect: '/login' }, // 重定向到login组件
//     {
//         path: '/login',
//         name: 'Login',
//         component: Login
//     },
//     {
//         path: '/home',
//         name: "Home",
//         component: Home
//     },
// ]





const router = new VueRouter({
        routes: [
            { path: '/', redirect: '/login' }, // 重定向到login组件
            {
                path: '/login',
                name: 'Login',
                component: Login
            },
            {
                path: '/home',
                name: "Home",
                component: Home,
                redirect: '/welcome',
              // 子路由
                  children:[
                    {
                      path : '/welcome',component:Welcome
                    },
                    {path: '/user',component: User},
                    {path:'/rights',component: Rights},
                    {path: '/roles',component: Roles},
                    {path: '/cate',component: Cate},
                    {path: '/params',component: Params},
                    
                  ]
            },
        ]
    })
    //挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//     // to：将要访问的路径； from：从哪个路径跳转来 next是一个方法，表示放行
//     if (to.path === '/login') return next();
//     //获取token
//     const tokenstr = window.sessionStorage.getItem('token');
//     // 判断没有token，跳转到登录页面
//     if (!tokenstr) {
//         return next('/login');
//     }
//     // 登录了，正常跳转
//     next();
// })
export default router
